import NP from 'number-precision'
import {
  getMarker,
  getTimeAndCountStr,
  getCurrentCountStr,
  getTheoreticalCountStr,
  getCurrentProbabilityStr,
  getTheoreticalProbabilityStr
} from '@/utils/study.js'

/**
 * @desc /one/order-bar-line
 */
export const formatterForOneSectionOrderBarLine = function (params) {
  const totalLength = this.allValues.length // 获取总长度
  let result = ''

  params.forEach((item) => {
    if (item.seriesType === 'bar') {
      // 号码数量
      const numberCount = 49
      // 每个号码理论出现次数
      const theoreticalAverage = NP.round(totalLength / numberCount, 2)
      // 每个号码理论出现概率，保留两位小数
      const theoreticalProbability = NP.round(NP.divide(100, numberCount), 2)
      // 当前概率
      const percentage = NP.round(NP.times(NP.divide(item.value, totalLength), 100), 2)
      // 红色
      const redMarker = getMarker('rgba(255, 112, 112,1)')

      result += `<div class="flex flex-col">
          ${getTimeAndCountStr(redMarker, item, totalLength)}
          ${getCurrentCountStr(item.value)}
          ${getTheoreticalCountStr(theoreticalAverage)}
          ${getCurrentProbabilityStr(percentage)}
          ${getTheoreticalProbabilityStr(theoreticalProbability)}
        </div>`
    }
  })
  return result
}
